package org.example.atry.myservlet;

import jakarta.servlet.GenericServlet;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.example.atry.service.agricultuerservicec;
import org.example.atry.service.impl.serviced;
import org.example.atry.util.Users;

import java.io.IOException;
import java.util.List;

@WebServlet (urlPatterns = {"/querysomesp"})
public class querysomesp extends GenericServlet {
    @Override

    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        // 设置允许跨域的头部信息
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
        response.setHeader("Access-Control-Allow-Headers", "Content-Type");
        response.setHeader("Access-Control-Max-Age", "3600");
        HttpSession session = request.getSession();
        String radio= (String) session.getAttribute("radio");
        agricultuerservicec serviced=new serviced();
        List<Users> cc=serviced.querysomesp(radio);
        request.setAttribute("cc", cc);
        request.getRequestDispatcher("querysomesp.jsp").forward(request, response);
        request.getSession().invalidate();

    }
}
